import GameShaderObj from "./GameShaderObj";
import CustomMaterial from "./CustomMaterial";

export default class HitShader extends GameShaderObj {
    static map: any = {};

    private sp: Laya.MeshSprite3D;

    origin: Laya.Material;
    custom: Laya.Material;

    constructor(sp: Laya.MeshSprite3D) {
        super();
        this.sp = sp;
        // console.log(sp)

        let cm: CustomMaterial = new CustomMaterial();
        cm.marginalColor = new Laya.Vector3(1, 0.02, 0.02);
        this.origin = sp.meshRenderer.sharedMaterial;
        this.custom = cm;
    }



    initShander(): void {


    }

    destroyShader(): void {
        if (!this.sp) {
            return;
        }
        var bdata = this.custom._shaderValues.getDataForNative();
        for (let key in bdata) {
            var data = bdata[key];
            if (data instanceof Laya.Texture2D) {
                data && data.destroy();
            }
        }
 
    }

    setShader() {
        this.sp.meshRenderer.sharedMaterial = this.custom;
    }

    clearShader() {
        this.sp.meshRenderer.sharedMaterial = this.origin;
    }


}